﻿using BLL;
using DAL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace HoteCode.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        public UserBLL UserBLL { get; }
        public ILogger<UserController> Logger { get; }

        public UserController(UserBLL userBLL, ILogger<UserController> logger)
        {
            UserBLL = userBLL;
            Logger = logger;
        }
        [HttpPost]
        /// <summary>
        /// 用户添加
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public IActionResult UserAdd(UserModel info)
        {
            try
            {
                var res= UserBLL.UserAdd(info);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// 用户管理员登录
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public IActionResult Login(string UserName, string Password)
        {
            try
            {
                
                var list=UserBLL.Login(UserName, Password);
                Logger.LogInformation($"用户{UserName}管理员正在登陆,登陆成功,登录时间为{DateTime.Now}");
                return Ok(list);
            }
            catch (Exception)
            {
                Logger.LogInformation($"用户{UserName}管理员正在登陆,登陆失败");
                throw;
            }
        }
    }
}
